package com.awesome.databindingdemo.databinding2.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;
import com.awesome.databindingdemo.R;
import com.awesome.databindingdemo.databinding.ItemSwordsmanBinding;
import com.awesome.databindingdemo.databinding2.bean.Swordsman;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Author: zhangjingfang
 * Email:zhangjingfang@jeejio.com
 * Date: 2021/7/29 11:14 下午
 * Description:类描述
 */
public class SwordsmanAdapter extends RecyclerView.Adapter<SwordsmanAdapter.SwordsmanHolder> {

    private List<Swordsman> mList;

    public SwordsmanAdapter(List<Swordsman> list) {
        mList = list;
    }

    @NonNull
    @NotNull
    @Override
    public SwordsmanHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        ItemSwordsmanBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_swordsman,parent,false);
        return new SwordsmanHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull SwordsmanHolder holder, int position) {

        Swordsman swordsman = mList.get(position);
        holder.getBinging().setSwordsman(swordsman);
    }


    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class SwordsmanHolder extends RecyclerView.ViewHolder{
        ItemSwordsmanBinding binging;

        public SwordsmanHolder(@NonNull ViewDataBinding binding) {
            super(binding.getRoot());
            this.binging = (ItemSwordsmanBinding) binding;
        }

        public ItemSwordsmanBinding getBinging() {
            return binging;
        }
    }
} 